/**
 * Created by Killer on 2016/1/5.
 */
function transparentShow(_this){
    _this.find(".transparent_class").show();
}
function transparentHide(_this){
    _this.find(".transparent_class").toggle();
}
var getCartoon= {
    /**
     * 获取视频更新内容
     * @param date,Kind(日期，分类【动漫、电视剧】)
     */
    getCartoon_Update:function(date){
        $.ajax({
            url:"/fallwings/Cartoon",
            type:"get",
            data:{date:date},
            statusCode:{
                200:function(data){
                    $("#"+date).find(".row").empty();
                    $.each(data,function(index){
                        var div1=$("<div></div>");//父
                        div1.addClass("col-sm-3 col-md-3");
                        var div21=$("<div></div>");//子
                        div21.addClass("media-left");
                        var a1=$("<a></a>");
                        a1.attr("href",data[index]["url"]);
                        a1.append("<img class=\"img-rounded\" src=\""+data[index]["colPicture"]+"\" height=\"70\" width=\"70\">");
                        var div22=$("<div></div>");
                        div22.addClass("media-body");
                        div22.css("width","200px");
                        div22.append("<h4 class=\"media-heading\"><a href=\""+data[index]["url"]+"\">"+data[index]["name"]+"</a></h4><h6>更新至：第"+data[index]["num"]+"集</h6>");
                        div21.append(a1);
                        div1.append(div21,div22);
                        $("#"+date).children('div').append(div1);
                    });

                }
            }
        });
    },
    /**
     * 视频排行
     */
    gerCartoon_Top_index:function(){
        $.ajax({
            url:"/fallwings/Cartoon/getList?order=2&size=7",
            type:"get",
            statusCode:{
                200:function(data){
                    $.each(data,function(index){
                        if(index==0){
                            $("#Cartoon_top_index_top1 img").attr("src",data[index]["rowPicture"]);
                            $("#Cartoon_top_index_top1").find("h1:eq(1)").text(data[index]["name"]);
                            $("#Cartoon_top_index_top1").find("h2:eq(0)").text("点击量："+data[index]["count"]);
                            $("#Cartoon_top_index_top1").find("h3:eq(0)").text("状态："+data[index]["status"]+" | "+data[index]["num"]+"集");
                        }
                        if(index>=1&&index<=2){
                            $("#Cartoon_top_index_top"+(index+1)+" img").attr("src",data[index]["rowPicture"]);
                            $("#Cartoon_top_index_top"+(index+1)).find("h4:eq(1)").text(data[index]["name"]);
                            $("#Cartoon_top_index_top"+(index+1)).find("h5:eq(0)").text("点击量："+data[index]["count"]);
                            $("#Cartoon_top_index_top"+(index+1)).find("h5:eq(1)").text("状态："+data[index]["status"]+" | "+data[index]["num"]+"集");
                        }
                        if(index>=3){
                            $("#cartoon_right").append(
                                "<div class='col-md-6 C-cartoon-right none-padding' style='position:relative' onmouseover='transparentShow($(this))' onmouseout='transparentHide($(this))'>"+
                                "<img src='' height='100%' width='100%' style='position: absolute'>"+
                                "<div class='max-width-height transparent_class' style='display: none;position:relative;z-index: 10;padding: 10px;background-color: #000000;color: #ffffff;'>"+
                                "<div><h3><span class='glyphicon glyphicon-list' style='float: left'>&nbsp;</span></h3>"+
                                "<h4 >"+data[index]["name"]+"</h4></div><div><h3><span class='glyphicon glyphicon-screenshot' style='float: left'>&nbsp;</span></h3>"+
                                "<h4>点击量："+data[index]["count"]+"</h4></div><div>"+
                                "<h3><span class='glyphicon glyphicon-exclamation-sign' style='float: left'>&nbsp;</span></h3>"+
                                "<h5>状态："+data[index]["status"]+" | "+data[index]["num"]+"集</h5></div><div style='text-align: center'>"+
                                "<a href='#' class='btn btn-default btn-sm' role='button'>详情</a>&nbsp;"+
                                "<a href='#' class='btn btn-default btn-sm' role='button' title='收藏'><span class='glyphicon glyphicon-star-empty' aria-hidden='true'></span></a>&nbsp;"+
                                "<a href='#' class='btn btn-default btn-sm' role='button' title='播放'>&nbsp;<span class='glyphicon glyphicon-play' aria-hidden='true'></span>&nbsp;</a>&nbsp;"+
                                "<a href='#' class='btn btn-default btn-sm' role='button' title='设为我的最爱'><span class='glyphicon glyphicon-heart-empty' aria-hidden='true'></span></a>"+
                                "</div> </div> </div>");
                        }
                    })
                }
            }
        })
    },
    getCartoon_Type_Init:function() {
        $.ajax({
            url: "/fallwings/Cartoon/getType?size=11",
            type: "get",
            statusCode: {
                200: function (data) {
                    $.each(data, function (index) {
                        var i="Cartoon_recommended" + index;
                        $("#Cartoon_recommended_more").parent().before(
                            "<li role='presentation' >" +
                            "<a href='#Cartoon_recommended" + index + "' aria-controls='Cartoon_recommended" + index + "' role='tab' data-toggle='tab'>" + data[index] + "</a></li>"
                        );
                        $("#Cartoon_recommended").find(".tab-content").append("" +
                        "<div role='tabpanel' class='tab-pane' id='Cartoon_recommended" + index + "'>" + "</div>");
                        if (index == 0) {
                            $("#Cartoon_recommended").find("ul li").addClass("active");
                            $("#Cartoon_recommended").find(".tab-content").find(".tab-pane").addClass("active");
                            $("#Cartoon_recommended_more").parent().removeClass("active");
                        }
                        $.ajax({
                            url:"/fallwings/Cartoon/getList?Type="+data[index]+"&size=4&order=0",
                            type:"get",
                            statusCode:{
                                200:function(data){
                                    $("#"+i).append("<div class='row'></div>");
                                    $.each(data,function(index){
                                        $("#"+i).find(".row").append("" +
                                            "<div class='col-sm-6 col-md-3'>"+
                                            "   <div class='thumbnail'>"+
                                            "       <img src='"+data[index]["colPicture"]+"' width='100%'>"+
                                            "       <div class='caption'>"+
                                            "           <h6><strong>"+data[index]["name"]+"</strong></h6>"+
                                            "           <h4><small>状态："+data[index]["status"]+"&nbsp;&nbsp;|&nbsp;&nbsp;"+data[index]["num"]+"集</small></h4>"+
                                            "           <p>" +
                                            "               <a href='#' class='btn btn-primary' role='button'>详情</a>" +
                                            "               <a href='#' class='btn btn-primary' role='button' title='收藏'><span class='glyphicon glyphicon-star-empty' aria-hidden='true'></span></a>" +
                                            "               <a href='#' class='btn btn-primary' role='button' title='播放'>&nbsp;<span class='glyphicon glyphicon-play' aria-hidden='true'></span>&nbsp;</a>" +
                                            "               <a href='#' class='btn btn-primary' role='button' title='设为我的最爱'><span class='glyphicon glyphicon-heart-empty' aria-hidden='true'></span></a>" +
                                            "           </p>"+
                                            "       </div>"+
                                            "   </div>"+
                                            "</div>"
                                        );
                                    })
                                }
                            }
                        })
                    })
                }
            }
        })
    }
}

$(document).ready(function(){
    getCartoon.getCartoon_Update("Monday");
    $("#Cartoon").find("li").click(function(){
        var type=$(this).parent().attr("id");
        getCartoon.getCartoon_Update(type);
    });
    $("#Cartoon_top_index_body").find(".float-left").height($("#Cartoon_top_index").width()*0.4);//排行框高度按宽度比例设置
    $("#cartoon_right").find(".col-md-6").height($("#cartoon_right").find(".col-md-6").width());
    getCartoon.gerCartoon_Top_index();
    getCartoon.getCartoon_Type_Init();
});